package com.example.demo.Topic.Consumer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class TopicConsumer {

    private static final Logger log = LoggerFactory.getLogger(TopicConsumer.class);

    //消费者1
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,//创建临时队列
            key = "test.*",
            exchange = @Exchange(name = "TopicExchange",type = "topic")
    ))
    public void Consumer1(String messages){
        log.info("Consumer1接收消息："+messages);
    }

    //消费者2
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue,//创建临时队列
            key = "test.#",
            exchange = @Exchange(name = "TopicExchange",type = "topic")
    ))
    public void Consumer2(String messages){
        log.info("Consumer2接收消息："+messages);
    }
}
